package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.CustomerCare;
import cn.gson.springboot.model.service.afterservice.CustomerCareService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/car")
public class CustomerCareController {

    @Autowired
    CustomerCareService sc;

    @RequestMapping("care-page")
    @ResponseBody
    public Map<String,Object> carePage(String types, String search, Integer currPage, Integer pageSize) {
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<CustomerCare> care = sc.selectCurePage(types,search);

        Map<String, Object> map = new HashMap<>();
        map.put("rows", obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total", obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("save-care")
    @ResponseBody
    public void saveCare(@RequestBody CustomerCare care){
        sc.addCare(care);
    }

    @RequestMapping("check-care")
    @ResponseBody
    public CustomerCare checkCare(Integer careId){
        return sc.selectByCareId(careId);
    }

    @RequestMapping("delete-care")
    @ResponseBody
    public void deleteCare(Integer careId){
        sc.deleteCareId(careId);
    }
}
